/*
 *  Class name: EditableTeamListItem.java
 *  Version: 1.0
 *  Date: 11.12.2013
 */
package cz.muni.fi.pa165.soccergamesarchive.restclient.gui.components.pageablelist.items.entity;

import cz.muni.fi.pa165.soccergamesarchive.businesslayer.dtos.TeamDTO;
import cz.muni.fi.pa165.soccergamesarchive.restclient.gui.components.pageablelist.PageableListPanel;
import cz.muni.fi.pa165.soccergamesarchive.restclient.gui.components.pageablelist.items.PageableListItemButton;
import cz.muni.fi.pa165.soccergamesarchive.restclient.gui.dialogs.TeamDetailDialogWindow;
import java.awt.Dialog;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import static cz.muni.fi.pa165.soccergamesarchive.restclient.utils.JOptionDialogWindowHandler.showYesNoDialogWindow;

/**
 *
 * @author Michal Ďuriš
 */
public class EditableTeamListItem extends PageableListItemButton<TeamDTO> {

    private static final long serialVersionUID = 1L;

    public EditableTeamListItem(PageableListPanel<TeamDTO> parentList,
                                TeamDTO entity) {
        super(parentList, entity);
    }

    @Override
    public void init() {
        setIcon(new ImageIcon(getClass().getResource(
                "/icons/components/team-icon.png")));
    }

    @Override
    public void setEntity(TeamDTO entity) {
        this.entity.setId(entity.getId());
        this.entity.setName(entity.getName());
        this.entity.setManagerName(entity.getManagerName());
        this.entity.setPlayers(entity.getPlayers());
    }

    @Override
    public String getEntityText() {
        return "<html> Name: " + entity.getName()
                + " <br> Manager name: " + entity.getManagerName();
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON1) {

            new TeamDetailDialogWindow(this, Dialog.ModalityType.MODELESS)
                    .init().setVisible(
                            true);

        } else if (e.getButton() == MouseEvent.BUTTON3) {

            if (showYesNoDialogWindow(parentList.getOwner(),
                    "Delete team", "Do you really want to delete this team ?")
                    == JOptionPane.YES_OPTION) {
                parentList.removeListItem(this, null);
            }
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

}
